package product_logic

import (
	"wx-uniapp-go/internal/repository/dto"
	"wx-uniapp-go/internal/repository/models"
	"wx-uniapp-go/third_party/oss"
)

// ListModel 获取模块列表
func (l *ProductLogic) ListModel() (*dto.LisModelResp, error) {
	where := "status = ?"
	var params []interface{}
	params = append(params, 1) // 只查询启用状态的分类

	// 获取分类列表
	var tags []*models.ProductModel
	err := models.Find(l.Ctx, &tags, where, params...)
	if err != nil {
		return nil, err
	}

	// 转换响应
	list := make([]*dto.ProductModel, len(tags))
	for i, tag := range tags {
		list[i] = &dto.ProductModel{
			Id:    tag.Id,
			Name:  tag.Name,
			Text:  tag.Text,
			Icon:  oss.Cli.JoinPath(tag.Icon),
			Color: tag.Color,
		}
	}

	return &dto.LisModelResp{
		List: list,
	}, nil
}
